<?php 
namespace Admin\Model;
use \Think\Model;

class TopicModel extends Model
{
    public function getTopic()
    {
        $res[] = '';
        import('ORG.Util.Page');
        $count = $this->count();
        $page = new \Think\Page($count,3);
        $show = $page->show();
        $data = $this->order('t_id')->limit($page->firstRow.','.$page->listRows)->order('t_id desc')->where('status=1')->select();

        // $data = $this->select();
        foreach ($data as $k => $v) {
                $uid = $this->table('dota2_user u,dota2_user_info ui')->field('email,nickname')->where('u.u_id=ui.ui_id and u.u_id='.$v['uid'])->select()[0];
                $data[$k]['email'] = $uid['email'];
                $data[$k]['nickname'] = $uid['nickname'];
                $data[$k]['content'] = htmlspecialchars($data[$k]['content']);
        }
        $res['data'] = $data;
        $res['page'] = $show;
        return $res;
    }

    public function checkuser($user)
    {
        $res = M('user')->field('u_id')->where('email="'.$user.'"')->select();
        if (!$res) {
            $res1 = M('user_info')->field('ui_id')->where('nickname="'.$user.'"')->select();
            if (!$res1) {
                return false;
            }else{
            return $res1[0]['ui_id'];
            }
            
        }
        return $res[0]['u_id'];
    }

    public function getBrash()
    {
        $res[] = '';
        import('ORG.Util.Page');
        $count = $this->where('status=0')->count();
        $page = new \Think\Page($count,3);
        $show = $page->show();
        $data = $this->order('t_id')->limit($page->firstRow.','.$page->listRows)->order('t_id desc')->where('status=0')->select();

        // $data = $this->select();
        foreach ($data as $k => $v) {
                $uid = $this->table('dota2_user u,dota2_user_info ui')->field('email,nickname')->where('u.u_id=ui.ui_id and u.u_id='.$v['uid'])->select()[0];
                $data[$k]['email'] = $uid['email'];
                $data[$k]['nickname'] = $uid['nickname'];
                $data[$k]['content'] = htmlspecialchars($data[$k]['content']);
        }
        $res['data'] = $data;
        $res['page'] = $show;
        return $res;
    }

}


